import { getDomain, request } from '@inbiz/utils';

export async function getPageTree(params: any) {
    return request(
        `/inbiz/api/services/engines/v${InbizConfig.API_VERSION}/page/loadTreeList`, {
        params,
    },
    );
};

// 通过站点域名获取应用信息
export async function getAppInfoByDomain() {
    return request(`/inbiz/api/services/front/engines/v${InbizConfig.API_VERSION}/app/info`, {
        params: {
            domain: getDomain(),
            getVersionInfo: true,
        },
    });
};

/**
 * 多语言语种增删改查
 * @param params 语种
 * @returns 
 */
export async function getAllLanguages() {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/kind`);
};

export async function createLanguages(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/language`, {
        method: 'POST',
        data: params,
    });
};

export async function deleteLanguages(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/language/delete`, {
        method: 'POST',
        data: params,
    });
};

export async function editLanguages(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/language`, {
        method: 'PUT',
        data: params,
    });
};

//获取多语言列表
export async function getLangList(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/language/page`, {
        method: 'POST',
        data: params,
    });
};

//获取组件多语言列表
export async function getComponentsLangList(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/componentLanguage/page`, {
        method: 'POST',
        data: params,
    });
};

export async function getSyncLang(appId: string) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/componentLanguage/sync/${appId}`, {
        timeout: 600000,
    });
};

//获取流程表单页面树
export async function getFormPageTree() {
    return request(`/inbiz/api/services/wfpage/v${InbizConfig.API_VERSION}/wfPage/pageList`);
};

//批量保存数据
export async function saveData(appId: string, params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/componentLanguage/saveDatas/${appId}`, {
        method: 'POST',
        data: params,
        timeout: 600000,
    });
};

//发布多语言
export async function publishLang(appId: string) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/language/publish/${appId}`);
};

export async function importLanguages(params: any) {
    return request(`/inbiz/api/hash/services/languagengine/v${InbizConfig.API_VERSION}/language/import`, {
        method: 'POST',
        data: params,
    });
};

export async function importLanguageProcess(params: any) {
    return request(`/inbiz/api/hash/services/languagengine/v${InbizConfig.API_VERSION}/language/processInfo`, {
        method: 'GET',
        params,
    });
};

//获取流程表单业务多语言
export async function getFormLangList(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/wFLanguage/queryPageList`, {
        method: 'POST',
        data: params,
    });
};

//编辑流程表单业务多语言
export async function editFormLang(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/wFLanguage`, {
        method: 'PUT',
        data: params,
    });
};

//删除流程表单业务多语言
export async function deleteFormLang(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/wFLanguage/delete`, {
        method: 'POST',
        data: params,
    });
};

// 获取版本列表
export async function getVersionData(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/language/dataVersionList`, {
        method: 'GET',
        params: {
            appId: params?.appId || '',
            siteOutId: params?.siteOutId || '',
        },
    });
};

// 获取普通页面的组件
export async function getComponents(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/componentLanguage/components`, {
        method: 'GET',
        params,
    });
};

// 获取表单页面的组件
export async function getFormComponents(params: any) {
    return request(`/inbiz/api/services/languagengine/v${InbizConfig.API_VERSION}/componentLanguage/page`, {
        method: 'POST',
        data: params,
    });
};